<?php
namespace App\Http\Controllers\Web;

use Illuminate\Http\Request;
use App\Models\V1\CommentModel;
use App\Http\Controllers\Controller;
use App\Common\ApiData;

class CommentController extends Controller{

    public function add_comment(Request $request){
        $pid        = $request->input('pid');
        $comment    = $request->input('comment');
        $userName   = $request->input('userName');
        $userId     = $request->input('userId',0);
        $type       = $request->input('type');
        $apiData    = new ApiData();


        $commentModel   = new CommentModel();
        $result         = $commentModel->add_comment($pid,$type,$comment,$userName,$userId);

        $apiData->code  = 200;
        $apiData->message   = "ok";
        return $apiData->send();
    }


    /**
     * 获得评论信息
     * */
    public function get_comments(Request $request){
        $pid    = $request->input('pid');
        $type   = $request->input('type');
        $apiData= new ApiData();

        $commentModel   = new CommentModel();
        $comments       = $commentModel->get_comments($pid,$type);
        $apiData->code = 200;
        $apiData->message   = "ok";
        return $apiData->set_data('comments',$comments)->send();
    }

    /**
     * 点赞信息
     *
     * */
    public function good_info(Request $request){
        $pid    = $request->input('pid');
        $type   = $request->input('type');
        $uid    = $request->input('uid',0);
        $model  = new CommentModel();
        $goodNumber = $model->count_good($pid,$type);
        $isSet  = $model->check_is_set_good($pid,$type,$uid);

        $apiData    = new ApiData();
        $apiData->code  = 200;
        $apiData->message   = "ok";
        return $apiData->set_data('goodNumber',$goodNumber)->set_data('isSet',$isSet)->send();
    }





    public function set_good(Request $request){
        $pid    = $request->input('pid');
        $type   = $request->input('type');
        $model  = new CommentModel();
        $userId = 0;
        $result = $model->set_good($pid,$type,$userId);
        $apiData = new ApiData();
        $apiData->code = 200;
        $apiData->message   = "ok";
        return $apiData->send();
    }

}